import 'package:flutter/material.dart';
import 'package:flutter_test_1/animation_test/animation_test_view.dart';
import 'package:flutter_test_1/image_picker/TestImagePicker.dart';
import 'package:flutter_test_1/image_picker/TestWechatImagePicker.dart';
import 'package:flutter_test_1/just_test/just_test_some_view.dart';
import 'package:flutter_test_1/listview_can_see_outside_item/listview_can_see_ouside_item_view.dart';
import 'package:flutter_test_1/snap_scroll_view/snap_scroll_page.dart';

import 'custom_scroll_view/custom_scroll_view_demo.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: DemoListView(),
      ),
      //隐藏右上角debug标签
      debugShowCheckedModeBanner: false,
    );
  }
}

class DemoListView extends StatelessWidget {
  DemoListView({Key? key}) : super(key: key);

  List<DemoItem> demoList = [
    DemoItem("CustomScrollView", const CustomScrollViewDemo()),
    DemoItem("just test some view", const JustTestSomeView()),
    DemoItem("snap scroll page", SnapScrollPage()),
    DemoItem("ListView can see outside item", const ListViewCanSeeOutsideItemView()),
    DemoItem("AnimationTestView", const AnimationTestView()),
    DemoItem("TestImagePicker", const TestImagePickerView()),
    DemoItem("TestWechatImagePicker", const TestWechatImagePicker()),
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Padding(
        padding: const EdgeInsets.only(top: 8),
        child: ListView.builder(
          itemCount: demoList.length,
          itemBuilder: (context, index) {
            var data = demoList[index];

            return Column(
              children: [
                GestureDetector(
                  onTap: () {
                    Navigator.push(context, MaterialPageRoute(builder: (context) => data.demo));
                  },
                  child: Padding(
                    padding: const EdgeInsets.only(top: 4),
                    child: Container(
                      color: Colors.lightBlue.withOpacity(0.5),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Text(
                          data.name,
                          style: TextStyle(
                              color: Colors.black, fontSize: 20, backgroundColor: Colors.amber.withOpacity(0.4)),
                        ),
                      ),
                    ),
                  ),
                ),
                const Padding(
                  padding: EdgeInsets.only(top: 4),
                  child: Divider(height: 1, color: Colors.black),
                )
              ],
            );
          },
        ),
      ),
    );
  }
}

class DemoItem {
  // 构造函数
  DemoItem(this.name, this.demo);

  String name;
  Widget demo;
}
